package timersession.ejb;

import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.ejb.Schedule;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.ejb.Timeout;
import javax.ejb.Timer;
import javax.ejb.TimerService;

/**
 * TimerBean is a singleton session bean that creates a timer and prints out a
 * message when a timeout occurs.
 */
@Singleton
public class TimerSessionBean {
    private static final Logger logger = Logger.getLogger(
                "TimerService Demo");
    @Resource
    TimerService timerService;
       
   @PostConstruct
    public void init() {
        long intervalDuration=5000;
        logger.log(
                Level.INFO,
                "Setting a programmatic timeout for {0} milliseconds from now.",
                intervalDuration);

        Timer timer = timerService.createTimer(
                    intervalDuration,
                    "Created new programmatic timer");
    }

    @Timeout
    public void programmaticTimeout(Timer timer) {
      
        logger.info("Programmatic timeout occurred.");
        Date t=new Date();
        logger.info(t.toString());
    }
      

    @Schedule(minute = "*/3", hour = "*")
    public void automaticTimeout() {
      
        logger.info("Automatic timeout occurred");
         Date t=new Date();
        logger.info(t.toString());
    }
     @Schedule(minute = "*/1", hour = "*")
    public void automaticTimeout2() {
      
        logger.info("Automatic timeout2 occurred");
         Date t=new Date();
        logger.info(t.toString());
    }

    
}
